package com.ruoyi.paipan.common;

import com.ruoyi.paipan.utils.LunarUtil;

import java.util.*;

public class EightChar {
    private int sect = 2;
    private Lunar lunar;
    private static LinkedHashMap<String,Integer> CHANG_SHENG_OFFSET = new LinkedHashMap<String,Integer>(){{
        put("甲" , 1);
        put("丙" , 10);
        put("戊" , 10);
        put("庚" , 7);
        put("壬" , 4);
        put("乙" , 6);
        put("丁" , 9);
        put("己" , 9);
        put("辛" , 0);
        put("癸" , 3);
    }};
    public static List<String> MONTH_ZHI = Arrays.asList("", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥", "子", "丑");
    public static List<String> CHANG_SHENG = Arrays.asList("长生", "沐浴", "冠带", "临官", "帝旺", "衰", "病", "死", "墓", "绝", "胎", "养");

    public EightChar(Lunar lunar) {
        this.lunar = lunar;
    }

    public static EightChar fromLunar(Lunar lunar)
    {
        return new EightChar(lunar);
    }

    @Override
    public String toString()
    {
        return this.getYear() + " " + this.getMonth() + " " + this.getDay() + " " + this.getTime();
    }


    public int getSect()
    {
        return this.sect;
    }

    public void setSect(int sect)
    {
        this.sect = (1 == sect) ? 1 : 2;
    }

    public Lunar getLunar()
    {
        return this.lunar;
    }

    public String getYear()
    {
        return this.lunar.getYearInGanZhiExact();
    }

    public String getYearGan()
    {
        return this.lunar.getYearGanExact();
    }

    public String getYearZhi()
    {
        return this.lunar.getYearZhiExact();
    }

    public List<String> getYearHideGan()
    {
        return LunarUtil.ZHI_HIDE_GAN.get(this.getYearZhi());
    }

    public String getYearWuXing()
    {
        return LunarUtil.WU_XING_GAN.get(this.getYearGan()) + LunarUtil.WU_XING_ZHI.get(this.getYearZhi());
    }

    public String getYearNaYin()
    {
        return LunarUtil.NAYIN.get(this.getYear());
    }

    public String getYearShiShenGan()
    {
        return LunarUtil.SHI_SHEN_GAN.get(this.getDayGan() + this.getYearGan());
    }

    private List<String> getShiShenZhi(String zhi)
    {
        List<String> hideGan = LunarUtil.ZHI_HIDE_GAN.get(zhi);
        List<String> l = new ArrayList<>();
        for (String s : hideGan) {
            l.add(LunarUtil.SHI_SHEN_ZHI.get(this.getDayGan() + zhi + s));
        }
        return l;
    }

    public List<String> getYearShiShenZhi()
    {
        return this.getShiShenZhi(this.getYearZhi());
    }

    private String getDiShi(int zhiIndex)
    {
        int index = EightChar.CHANG_SHENG_OFFSET.get(this.getDayGan()) + (this.getDayGanIndex() % 2 == 0 ? zhiIndex : 0 - zhiIndex);
        if (index >= 12) {
            index -= 12;
        }
        if (index < 0) {
            index += 12;
        }
        return EightChar.CHANG_SHENG.get(index);
    }

    public String getYearDiShi()
    {
        return this.getDiShi(this.lunar.getYearZhiIndexExact());
    }

    public String getMonth()
    {
        return this.lunar.getMonthInGanZhiExact();
    }

    public String getMonthGan()
    {
        return this.lunar.getMonthGanExact();
    }

    public String getMonthZhi()
    {
        return this.lunar.getMonthZhiExact();
    }

    public List<String> getMonthHideGan()
    {
        return LunarUtil.ZHI_HIDE_GAN.get(this.getMonthZhi());
    }

    public String getMonthWuXing()
    {
        return LunarUtil.WU_XING_GAN.get(this.getMonthGan()) + LunarUtil.WU_XING_ZHI.get(this.getMonthZhi());
    }

    public String getMonthNaYin()
    {
        return LunarUtil.NAYIN.get(this.getMonth());
    }

    public String getMonthShiShenGan()
    {
        return LunarUtil.SHI_SHEN_GAN.get(this.getDayGan() + this.getMonthGan());
    }

    public List<String> getMonthShiShenZhi()
    {
        return this.getShiShenZhi(this.getMonthZhi());
    }

    public String getMonthDiShi()
    {
        return this.getDiShi(this.lunar.getMonthZhiIndexExact());
    }

    public String getDay()
    {
        return (2 == this.sect) ? this.lunar.getDayInGanZhiExact2() : this.lunar.getDayInGanZhiExact();
    }

    public String getDayGan()
    {
        return (2 == this.sect) ? this.lunar.getDayGanExact2() : this.lunar.getDayGanExact();
    }

    public String getDayZhi()
    {
        return (2 == this.sect) ? this.lunar.getDayZhiExact2() : this.lunar.getDayZhiExact();
    }

    public List<String> getDayHideGan()
    {
        return LunarUtil.ZHI_HIDE_GAN.get(this.getDayZhi());
    }

    public String getDayWuXing()
    {
        return LunarUtil.WU_XING_GAN.get(this.getDayGan()) + LunarUtil.WU_XING_ZHI.get(this.getDayZhi());
    }

    public String getDayNaYin()
    {
        return LunarUtil.NAYIN.get(this.getDay());
    }

    public String getDayShiShenGan()
    {
        return "日主";
    }

    public List<String> getDayShiShenZhi()
    {
        return this.getShiShenZhi(this.getDayZhi());
    }

    public int getDayGanIndex()
    {
        return (2 == this.sect) ? this.lunar.getDayGanIndexExact2() : this.lunar.getDayGanIndexExact();
    }

    public int getDayZhiIndex()
    {
        return (2 == this.sect) ? this.lunar.getDayZhiIndexExact2() : this.lunar.getDayZhiIndexExact();
    }

    public String getDayDiShi()
    {
        return this.getDiShi(this.getDayZhiIndex());
    }

    public String getTime()
    {
        return this.lunar.getTimeInGanZhi();
    }

    public String getTimeGan()
    {
        return this.lunar.getTimeGan();
    }

    public String getTimeZhi()
    {
        return this.lunar.getTimeZhi();
    }

    public List<String> getTimeHideGan()
    {
        return LunarUtil.ZHI_HIDE_GAN.get(this.getTimeZhi());
    }

    public String getTimeWuXing()
    {
        return LunarUtil.WU_XING_GAN.get(this.lunar.getTimeGan()) + LunarUtil.WU_XING_ZHI.get(this.lunar.getTimeZhi());
    }

    public String getTimeNaYin()
    {
        return LunarUtil.NAYIN.get(this.getTime());
    }

    public String getTimeShiShenGan()
    {
        return LunarUtil.SHI_SHEN_GAN.get(this.getDayGan() + this.getTimeGan());
    }

    public List<String> getTimeShiShenZhi()
    {
        return this.getShiShenZhi(this.getTimeZhi());
    }

    public String getTimeDiShi()
    {
        return this.getDiShi(this.lunar.getTimeZhiIndex());
    }

    public String getTaiYuan()
    {
        int ganIndex = this.lunar.getMonthGanIndexExact() + 1;
        if (ganIndex >= 10) {
            ganIndex -= 10;
        }
        int zhiIndex = this.lunar.getMonthZhiIndexExact() + 3;
        if (zhiIndex >= 12) {
            zhiIndex -= 12;
        }
        return LunarUtil.GAN.get(ganIndex + 1) + LunarUtil.ZHI.get(zhiIndex + 1);
    }

    public String getTaiYuanNaYin()
    {
        return LunarUtil.NAYIN.get(this.getTaiYuan());
    }

    public String getTaiXi()
    {
        int ganIndex = (2 == this.sect) ? this.lunar.getDayGanIndexExact2() : this.lunar.getDayGanIndexExact();
        int zhiIndex = (2 == this.sect) ? this.lunar.getDayZhiIndexExact2() : this.lunar.getDayZhiIndexExact();
        return LunarUtil.HE_GAN_5.get(ganIndex) + LunarUtil.HE_ZHI_6.get(zhiIndex);
    }

    public String getTaiXiNaYin()
    {
        return LunarUtil.NAYIN.get(this.getTaiXi());
    }

    public String getMingGong()
    {
        int monthZhiIndex = 0;
        int timeZhiIndex = 0;
        for (int i = 0, j = EightChar.MONTH_ZHI.size(); i < j; i++) {
            String zhi = EightChar.MONTH_ZHI.get(i);
            if (Objects.equals(this.lunar.getMonthZhiExact(), zhi)) {
                monthZhiIndex = i;
            }
            if (Objects.equals(this.lunar.getTimeZhi(), zhi)) {
                timeZhiIndex = i;
            }
        }
        int zhiIndex = 26 - (monthZhiIndex + timeZhiIndex);
        if (zhiIndex > 12) {
            zhiIndex -= 12;
        }
        int jiaZiIndex = LunarUtil.getJiaZiIndex(this.lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
        if (jiaZiIndex >= 60) {
            jiaZiIndex -= 60;
        }
        if (jiaZiIndex < 0) {
            jiaZiIndex += 60;
        }
        return LunarUtil.JIA_ZI.get(jiaZiIndex);
    }

    public String getMingGongNaYin()
    {
        return LunarUtil.NAYIN.get(this.getMingGong());
    }

    public String getShenGong()
    {
        int monthZhiIndex = 0;
        int timeZhiIndex = 0;
        for (int i = 0, j = EightChar.MONTH_ZHI.size(); i < j; i++) {
            String zhi = EightChar.MONTH_ZHI.get(i);
            if (this.lunar.getMonthZhiExact() == zhi) {
                monthZhiIndex = i;
            }
            if (this.lunar.getTimeZhi() == zhi) {
                timeZhiIndex = i;
            }
        }
        int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
        if (zhiIndex > 12) {
            zhiIndex -= 12;
        }
        int jiaZiIndex = LunarUtil.getJiaZiIndex(this.lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
        if (jiaZiIndex >= 60) {
            jiaZiIndex -= 60;
        }
        if (jiaZiIndex < 0) {
            jiaZiIndex += 60;
        }
        return LunarUtil.JIA_ZI.get(jiaZiIndex);
    }

    public String getShenGongNaYin()
    {
        return LunarUtil.NAYIN.get(this.getShenGong());
    }

    public Yun getYun(int gender)
    {
        return this.getYunBySect(gender, 1);
    }

    public Yun getYunBySect(int gender, int sect)
    {
        return new Yun(this, gender, sect);
    }

    public String getYearXun()
    {
        return this.lunar.getYearXunExact();
    }

    public String getYearXunKong()
    {
        return this.lunar.getYearXunKongExact();
    }

    public String getMonthXun()
    {
        return this.lunar.getMonthXunExact();
    }

    public String getMonthXunKong()
    {
        return this.lunar.getMonthXunKongExact();
    }

    public String getDayXun()
    {
        return (2 == this.sect) ? this.lunar.getDayXunExact2() : this.lunar.getDayXunExact();
    }

    public String getDayXunKong()
    {
        return (2 == this.sect) ? this.lunar.getDayXunKongExact2() : this.lunar.getDayXunKongExact();
    }

    public String getTimeXun()
    {
        return this.lunar.getTimeXun();
    }

    public String getTimeXunKong()
    {
        return this.lunar.getTimeXunKong();
    }

    public static void main(String[] args) {
        int s =1;
        String a = "02:01";
        String b ="01:00";
        int i = 4 % 5;

        System.out.println(((4 % 5) * 2 + 1) % 10);
    }
}
